home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / locvecto.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  4.1 KB  |  137 lines

  1. #ifndef __LOCALE_VECTOR
  2. #define __LOCALE_VECTOR
  3. #pragma option push -b -a4 -Vx- -Ve- -w-inl -w-aus -w-sig
  4.  
  5. /***************************************************************************
  6.  *
  7.  * locvector - Declarations for locales local vector class
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * (c) Copyright 1994, 1995 Rogue Wave Software, Inc.
  12.  * ALL RIGHTS RESERVED *
  13.  * The software and information contained herein are proprietary to, and
  14.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  15.  * intends to preserve as trade secrets such software and information.
  16.  * This software is furnished pursuant to a written license agreement and
  17.  * may be used, copied, transmitted, and stored only in accordance with
  18.  * the terms of such license and with the inclusion of the above copyright
  19.  * notice.  This software and information or any other copies thereof may
  20.  * not be provided or otherwise made available to any other person.
  21.  *
  22.  * Notwithstanding any other lease or license that may pertain to, or
  23.  * accompany the delivery of, this computer software and information, the
  24.  * rights of the Government regarding its use, reproduction and disclosure
  25.  * are as set forth in Section 52.227-19 of the FARS Computer
  26.  * Software-Restricted Rights clause.
  27.  * 
  28.  * Use, duplication, or disclosure by the Government is subject to
  29.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  30.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  31.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  32.  * P.O. Box 2328, Corvallis, Oregon 97339.
  33.  *
  34.  * This computer software and information is distributed with "restricted
  35.  * rights."  Use, duplication or disclosure is subject to restrictions as
  36.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  37.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  38.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  39.  * then the "Alternate III" clause applies.
  40.  *
  41.  **************************************************************************/
  42.  
  43. #ifndef _RWSTD_NO_NAMESPACE
  44. namespace __rwstd {
  45. using namespace std;
  46. #endif
  47.  
  48.  
  49. // Minute vector class
  50. template <class T>
  51. class locale_vector
  52. {
  53. public:
  54.     typedef size_t size_type;
  55.     typedef ptrdiff_t difference_type;
  56.     typedef T value_type;
  57.     typedef T& reference;
  58.     typedef T* pointer;
  59.     typedef T* iterator;
  60.  
  61. private:
  62.   iterator first_;
  63.   size_type size_;
  64.  
  65. public:
  66.   locale_vector() : first_(0), size_(0) {;}
  67.   locale_vector(size_type n) : first_(0), size_(n) 
  68.   {
  69.     if (n)
  70.       first_ = new T[n];
  71.   }
  72.   locale_vector(size_type n, const T& v) : first_(0), size_(n) 
  73.   {
  74.     if (n)
  75.       first_ = new T[n];
  76.     while (n)
  77.       first_[--n] = v;
  78.   }
  79.   locale_vector(const locale_vector<T>& lv) : first_(0), size_(0)
  80.   {
  81.     size_type n = size_ = lv.size();
  82.     if (n)
  83.       first_ = new T[n];
  84.     while (n--)
  85.       first_[n] = lv[n];
  86.   }    
  87.   ~locale_vector() { if (first_) delete [] first_;}
  88.   const locale_vector& operator= (const locale_vector& lv) 
  89.   {
  90.     size_type n = size_ = lv.size();
  91.     if (first_)
  92.       delete [] first_;
  93.     if (n)
  94.       first_ = new T[n];
  95.     while (n--)
  96.       first_[n] = lv[n];
  97.     return *this;
  98.   }
  99.   iterator begin() const { return iterator(first_); }
  100.   iterator end() const { return iterator(first_+size_); }    
  101.   size_type size() const { return size_; }
  102.  
  103.   T& operator[] (size_t i) { return first_[i]; }
  104.   const T& operator[] (size_t i) const { return first_[i]; }
  105.  
  106.   // Resize array and copy old contents to new buffer. 
  107.   iterator resize(size_t s)
  108.   { 
  109.      return resize(s,T()); 
  110.   }
  111.   iterator resize(size_t s, T v)
  112.   {
  113.     T *new_buf = new T[s];
  114.     iterator j,k;
  115.     size_type d = size_ < s ? size_ : s;
  116.  
  117.     for (j = first_, k = new_buf; j != first_+d; j++,k++)
  118.       *k =  *j;
  119.  
  120.     while (d < s)
  121.       new_buf[d++] = v;
  122.  
  123.     if (first_)
  124.       delete [] first_;    
  125.     first_ = new_buf;
  126.     size_ = s;
  127.     return first_;
  128.   }
  129. };
  130.  
  131. #ifndef _RWSTD_NO_NAMESPACE
  132. } // namespace __rwstd
  133. #endif
  134.  
  135. #pragma option pop
  136. #endif // __LOCALE_VECTOR
  137.